package cn.edu.gdpt.mobile213.mobile2121606097wjc0514;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;

public class MainActivity extends AppCompatActivity {
    private CheckBox chkboxMainYinqing;
    private CheckBox chkboxMainQianboli;
    private CheckBox chkboxMainluntai;
    private CheckBox chkboxMainDipang;
    private CheckBox chkboxMainQiangai;
    private CheckBox chkboxMainXuangua;
    private CheckBox chkboxMainZuoyi;
    private CheckBox chkboxMainFanxiangpang;
    private CheckBox chkboxMainChejia;
    private CheckBox chkboxMainChemen;
    private CheckBox chkboxMainHouboli;
    private Button btnMainShopping;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        btnMainShopping.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String carParts="";
                if (chkboxMainYinqing.isChecked()==true){
                    carParts+=chkboxMainYinqing.getText().toString()+"\n";
                }if (chkboxMainQianboli.isChecked()==true){
                    carParts+=chkboxMainQianboli.getText().toString()+"\n";
                }if (chkboxMainluntai.isChecked()==true){
                    carParts+=chkboxMainluntai.getText().toString()+"\n";
                }if (chkboxMainDipang.isChecked()==true){
                    carParts+=chkboxMainDipang.getText().toString()+"\n";
                }if (chkboxMainQiangai.isChecked()==true){
                    carParts+=chkboxMainQiangai.getText().toString()+"\n";
                }if (chkboxMainXuangua.isChecked()==true){
                    carParts+=chkboxMainXuangua.getText().toString()+"\n";
                }if (chkboxMainZuoyi.isChecked()==true){
                    carParts+=chkboxMainZuoyi.getText().toString()+"\n";
                }if (chkboxMainFanxiangpang.isChecked()==true){
                    carParts+=chkboxMainFanxiangpang.getText().toString()+"\n";
                }if (chkboxMainChejia.isChecked()==true){
                    carParts+=chkboxMainChejia.getText().toString()+"\n";
                }if (chkboxMainChemen.isChecked()==true){
                    carParts+=chkboxMainChemen.getText().toString()+"\n";
                }if (chkboxMainHouboli.isChecked()==true){
                    carParts+=chkboxMainHouboli.getText().toString()+"\n";
                }
                if (carParts==""){
                    new AlertDialog.Builder(MainActivity.this)
                            .setMessage("请选择原材料")
                            .setPositiveButton("确定",null )
                            .create()
                            .show();
                }else {
                    Intent intent=new Intent();
                    intent.putExtra("carParts",carParts);
                    setResult(RESULT_OK,intent);
                    finish();
                }
            }
        });
    }

    private void initView() {
        chkboxMainYinqing=(CheckBox) findViewById(R.id.chkboxMainYinqing);
        chkboxMainQianboli=(CheckBox) findViewById(R.id.chkboxMainQingboli);
        chkboxMainluntai=(CheckBox) findViewById(R.id.chkboxMainLuntai);
        chkboxMainDipang=(CheckBox) findViewById(R.id.chkboxMainDipang);
        chkboxMainQiangai=(CheckBox) findViewById(R.id.chkboxMainQiangai);
        chkboxMainXuangua=(CheckBox) findViewById(R.id.chkboxMainXuangua);
        chkboxMainZuoyi=(CheckBox) findViewById(R.id.chkboxMainZuoyi);
        chkboxMainFanxiangpang=(CheckBox) findViewById(R.id.chkboxMainFanxiangpang);
        chkboxMainChejia=(CheckBox) findViewById(R.id.chkboxMainChejia);
        chkboxMainChemen=(CheckBox) findViewById(R.id.chkboxMainChemen);
        chkboxMainHouboli=(CheckBox) findViewById(R.id.chkboxMainHouboli);
        btnMainShopping=(Button) findViewById(R.id.btnMainShopping);
    }
}